<?php
use Service\UserService;
class FundModel extends BaseModel
{
    //表名
    protected $table = 'fund';
    private static $alertStr = "您当前的风险评级为%s，低于此产品的风险等级%s。您需要重新测评，当您的风险评级高于或等于此产品的风险等级才能查看产品详情，否则将无法查看。";

    public static function classifyList($list,$uId)
    {
        //获取用户当前等级
        $score = EvaluationModel::select('evaluation_score')->where('uid', $uId)->first();
        $userlevel = UserService::getInstance()->getGrade($score['evaluation_score']);
        $result = array();
        if ($list) {
            foreach ($list as $value) {
                if($userlevel['grade_int'] >= $value['risk_rank'])
                {
                    $value['risk_text'] = '';
                }else{
                    $value['risk_text'] = sprintf(self::$alertStr,$userlevel['grade'],'R'.$value['risk_rank']);
                }
                $value['fund_risk_level'] = getProductRiskDescription($value['risk_rank']);
                array_push($result, $value);
            }
        }
        return $result;
    }

    // 检查是否可预约
    public static function validConsultStatus($id)
    {
        $fundDetail = static::query()->find($id);
        if ($fundDetail['status'] != 0) {
            return '基金已售罄';
        }
        if ($fundDetail['pattern'] != 0) {
            return '基金已下架';
        }

        return true;
    }
}
